<template>
	<view class="shoplist">

		<view class="listWrapper">
			<view class="item" v-for="item in dataList">
				<view class="title">{{item.ProName}}</view>
				<view class="item-wrapper">
					<view><text class="xx">成本价：</text>¥{{(item.Cost/100).toFixed(2)}}</view>
					<view><text class="xx">售价：</text>¥{{(item.Price/100).toFixed(2)}}</view>
				</view>
				<view class="item-wrapper">
					<view><text class="xx">库存：</text>{{item.Stock}}</view>
					<view><text class="xx">销量：</text>{{item.Sales}}</view>
				</view>
				
				<view><text class="xx">上架时间：</text>{{item.addtime_str}}</view>
				<view><text class="xx">条形码：</text>{{item.BarCode}}</view>
				<view class="actionWrapper">
					<view class="bianji" v-on:click="onEdit(item)">编辑</view>
				</view>
			</view>
		</view>
		<view class="emptyWrapper" v-if="dataList.length==0">
			<image src="../../static/zanwushangpin.png" mode="aspectFit"></image>
			<view class="title">暂无商品</view>
		</view>
		<view class="header">
			<view v-on:click="onCate" class="cate" v-if="cateText.length==0">全部<image src="../../static/arrowdown.png"></image></view>
			<view v-on:click="onCate" class="cate" v-if="cateText.length>0">{{cateText}}<image src="../../static/arrowdown.png"></image></view>
			<input class="search" placeholder="请输入关键字" v-model="keyword" />
			<text class="btn" @click="doSearch">搜索</text>
		</view>
		<view class="buttonWrapper">
			<view class="shangjia" v-on:click="onShangJia">上架商品</view>
			<view class="ruku" v-on:click="onruku">商品入库</view>
		</view>
	</view>
</template>

<script>
	import http from "../../common/http.js"
	import common from "../../common/common.js"
	export default {
		data() {
			return {
				keyword:"",
				storeid:0,
				dataList:[],
				isLoadingMore:false,
				page:1,
				noMore:true,
				next:{"pages":1,"keyword":"","cateid":0,"storeid":this.storeid},
				cateText:'',
				cateItem:{}
			}
		},
		onLoad(options) {
			var self = this 
			this.storeid = options.storeid
			this.next={"pages":1,"keyword":"","cateid":0,"storeid":this.storeid}
			this.refreshData()
		},
		onPullDownRefresh() {
			this.isLoadingMore = false
			this.next.pages = 1
			this.refreshData()
			
		},
		onReachBottom() {
			if (this.noMore == false) {
				this.isLoadingMore = true
				this.refreshData()
			}
		},
		onShow() {
			var cateItem = uni.getStorageSync("cate")
			console.log(cateItem)
			if (cateItem.length == 0) {return}
			// if (cateItem == void 0) {
			// 	return
			// }
			this.cateText = cateItem.Name
			uni.removeStorageSync("cate")
		},
		methods: {
			refreshData() {
				var self = this
				self.next['cateid'] = this.cateItem.Id
				http.get("/store/goods/list", self.next, (r)=>{
					uni.stopPullDownRefresh()
					self.next=r.next
					for (var i=0;i<r.data.length;i++) {
						r.data[i]["addtime_str"] = common.formatTime(r.data[i]["AddTime"])
						console.log(r.data[i]["addtime_str"])
					}
					
				
					if (self.isLoadingMore) {
						self.dataList = self.dataList.concat(r.data)
					}else{
						self.dataList = r.data
					}
					
					if (r.data.length == 0) {
						self.noMore = true
					}else{
						self.noMore = false
					}
				})
			},
			onShangJia(){				
				uni.navigateTo({
					url:"../addshop/addshop?storeid="+this.storeid
				})
			},
			onruku(){
				uni.navigateTo({
					url:"../stock/stock?storeid="+this.storeid
				})
			},
			onEdit(e) {
				console.log(e)
				uni.navigateTo({
					url:"../editshop/editshop?id="+e.Id+"&storeid="+this.storeid
				})
			},
			
			doSearch(){
				var self=this
				self.next.pages=1
				self.next.keyword=self.keyword
				self.isLoadingMore=false
				self.refreshData()
				//self.keyword=""
			},
			onCate() {
				uni.navigateTo({
					url:"../cate/cate?from=search"
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #f3f3f2;
	}
	.shoplist {
		background-color: #f3f3f2;
	}
	.listWrapper {
		padding-top: 50px;
		box-sizing: border-box;
		padding-bottom: 100px;
	}
	.item {
		background-color: white;
		margin-bottom: 10px;
		padding: 15px;
		box-sizing: border-box;
		color: #333333;
		font-size: 15px;
		border-radius: 8px;
		
	}
	.item-wrapper{
		display: flex;
		height: 20px;
	}
	.item-wrapper view{
		width: 50%;
	}
	.item .title {
		font-size: 13px;
		font-weight: bold;
		color: #333333;
		margin-bottom: 10px;
	}
	.xx {
		color: #999999;
		font-size: 13px;
		width: 70px;
		display: inline-block;
	}
	.buttonWrapper {
		position: fixed;
		background-color: #F3F3F2;
		bottom: 0px;
		display: flex;
		background-color: white;
		bottom: 0px;
		width: 100%;
		height: 60px;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 0 15px;
		box-sizing: border-box;
		box-shadow: 1px -1px 3px #DEDEDE;
	}
	.shangjia {
		width: 50%;
		text-align: center;
		background-color: #007AFF;
		height: 50px;
		line-height: 50px;
		color: white;
		margin-right: 10px;
		border-radius: 10px;
	}
	.actionWrapper {
		height: 25px;
	}
	.ruku {
		width: 50%;
		background-color: #F0AD4E;
		color: white;
		color: white;
		text-align: center;
		height: 50px;
		line-height: 50px;
		border-radius: 10px;
	}
	.bianji {
		color: #75D7E0;
		border:1px solid #75D7E0;
		font-size: 13px;
		width: 82px;
		border-radius: 18px;
		text-align: center;
		line-height: 25px;
		height: 25px;
		float: right;
	}
	.header{
		display: flex;
		position: fixed;
		top: 0px;
		width: 100%;
		background-color: white;
		box-shadow: 1px 1px 3px #DEDEDE;
		align-items: center;
		height: 50px;
	}
	.header .cate {
		flex-shrink: 0;
		padding-left: 15px;
		display: flex;
		align-items: center;
	}
	.header .cate image {
		width: 20px;
		height: 20px;
	}
	.search{
		width: 80%;
		background-color: #f3f3f2;
		height: 40px;
		padding: 0 10px;
		box-sizing: border-box;
		margin-left: 10px;
	}
	.btn{
		margin: 32rpx 0;
		background-color: #4e6ef2;
		width: 100px;
		height: 40px;
		text-align: center;
		line-height: 40px;
		font: 16px;
		text-align: center;
		color: white;
		margin-right: 10px;
	}
</style>
